package com.exam.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.exam.handler.StpHandler;
import com.exam.service.AnalysisService;
import com.exam.utils.ResultBody;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "成绩分析管理")
@RestController
@RequestMapping(value = "/analysis")
public class AnalysisController{

    @Autowired
    private AnalysisService analysisService;

    @GetMapping("/getStudentGradeByNum")
    @ApiOperation("获取学生考试的分数分布")
    @SaCheckPermission("student")
    public ResultBody getStudentGradeByNum(){
        return ResultBody.success(analysisService.getStudentGradeByNum(StpHandler.getId()));
    }


    @GetMapping("/getGradeTrend")
    @ApiOperation("获取学生考试这门课的考试分数变化")
    @SaCheckPermission("student")
    public ResultBody getGradeTrend(@RequestParam("lessonId") Integer lessonId){
        return ResultBody.success(analysisService.getGradeTrend(StpHandler.getId(), lessonId));
    }

    @GetMapping("/getAllGradeByExamId/{examId}")
    @ApiOperation("获取单次考试的分数分布")
    @SaCheckPermission("teacher")
    public ResultBody getAllGradeByExamId(@PathVariable Integer examId){
        return ResultBody.success(analysisService.getAllGradeByExamId(examId));
    }

    @GetMapping("/getAllGradeByLessonId/{lessonId}")
    @ApiOperation("获取班级所有考试的分数分布")
    @SaCheckPermission("teacher")
    public ResultBody getAllGradeByLessonId(@PathVariable Integer lessonId){
        return ResultBody.success(analysisService.getAllGradeByLessonId(lessonId));
    }

    @GetMapping("/getRadarByStudentIdAndLessonId/{lessonId}")
    @ApiOperation("获取学生在班级所有考试的知识点得分情况")
    @SaCheckPermission("student")
    public ResultBody getRadarByStudentIdAndLessonId(@PathVariable Integer lessonId){
        return ResultBody.success(analysisService.getAllKnowledgeGradeByLessonId(lessonId,StpHandler.getId()));
    }

}
